{include file="public/head"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"> 批量发货</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form" wid100 lay-filter="form">

                        <div class="layui-form-item">
                            <label class="layui-form-label">使用说明</label>
                            <div class="layui-col-md4">
                                <p>如重复导入数据将以最新导入数据为准，请谨慎使用</p>
                                <p>数据导入订单状态自动修改为已发货</p>
                                <p>一次导入的数据不要超过{:config('self.batch_send_max')}条</p>
                                <p>使用方法:</p>
                                <p>1. 下载Excel模板文件并录入信息</p>
                                <p>2. 选择快递公司</p>
                                <p>3. 上传Excel导入</p>
                                <p>格式要求： Excel第一列必须为订单单号，第二列必须为快递单号，请确认订单单号与快递单号的备注</p>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">快递公司</label>
                            <div class="layui-input-inline">
                                <select name="send_express_id" lay-verify="required" lay-search>
                                    <option value="">请选择快递公司</option>
                                    {volist name="express" id="vo"}
                                    {if $vo['status']==1}
                                    <option value="{$vo.id}">{$vo.title}</option>
                                    {/if}
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">Excel</label>
                            <div class="layui-input-inline">
                                <input name="excel" id="excel" readonly lay-verify="required" placeholder="请上传Excel" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                <button type="button" class="layui-btn" id="upload">
                                    <i class="layui-icon">&#xe67c;</i>上传Excel
                                </button>
                            </div>
                            <div class="layui-form-mid layui-word-aux">如果遇到数据重复则将进行数据更新</div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id">
                                <button class="layui-btn" lay-submit lay-filter="edit-btn">确认导入</button>
                                <a href="{:addHttp('/batch_send_excel.xls')}" class="layui-btn layui-btn-normal">下载Excel导入模板</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script>
    layui.config({
        base: '__LAYADMIN__/',
        version: 20220407
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','upload'],function(){
        var $=layui.$,admin=layui.admin,form = layui.form,upload=layui.upload;

        //提交
        form.on('submit(edit-btn)', function (data) {
            $.ajax({
                url: "{:url('Order/batchSend')}",
                type: 'POST', //GET
                async: true,    //或false,是否异步
                data: data.field,
                timeout: 5000,    //超时时间
                dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                success: function (json) {
                    if(json.code==0){

                        var show_content = "<div style='padding:20px;'>";

                        show_content += "<p style='line-height: 30px;border-bottom: 1px solid #ccc;'>共计："+json.data.all_num+"条 失败："+json.data.fail_num+"条 成功："+json.data.success_num+"条</p>"

                        for(var ii=0;ii<json.data.fail_arr.length;ii++){
                            show_content += "<p style='line-height: 30px;color:red;border-bottom: 1px dashed #ccc;'>"+json.data.fail_arr[ii]+"</p>";
                        }
                        for(var ii=0;ii<json.data.success_arr.length;ii++){
                            show_content += "<p style='line-height: 30px;color:green;border-bottom: 1px dashed #ccc;'>"+json.data.success_arr[ii]+"</p>";
                        }

                        show_content += "</div>";

                        layer.open({
                            type: 1,
                            title: '导入结果',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['70%','70%'],
                            content: show_content
                        });
                    }else{
                        layer.msg(json.msg);
                        return false;
                    }
                }
            });


        });

        upload.render({
            url: '{:url(\'Upfiles/upExcel\')}'
            , elem: '#upload'
            , accept:'file'
            , exts:'xls|xlsx'
            , done: function (res) {
                if (res.code == 0) {
                    $("#excel").val(res.url);
                } else {
                    layer.msg(res.info, {icon: 5});
                }
            }
        });

    });
</script>
</body>
</html>